package com.fish.spider.util;

import com.google.common.base.Splitter;
import com.google.common.collect.Maps;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;

public class BaiduDecryptionUtil {
    /**
     * 解密算法
     *
     * @param key  密钥
     * @param data 加密的数据
     * @return 解密之后的字符串数据
     */
    public static String decryption(List<String> key, List<String> data) {
        Map<String, String> map = Maps.newHashMap();
        for (int i = 0; i < key.size() / 2; i++) {
            map.put(key.get(i), key.get(key.size() / 2 + i));
        }
        StringBuilder decrypt_data = new StringBuilder();
        for (String datum : data) {
            decrypt_data.append(map.get(datum));
        }
        return decrypt_data.toString();
    }

    public static String decryption(String key,String data) {
        String[] dataArr = data.split("");
        String[] keyArr = key.split("");
        List<String> keyList = new ArrayList<>(data.length());
        List<String> dataList = new ArrayList<>(data.length());
        keyList.addAll(Arrays.asList(keyArr));
        dataList.addAll(Arrays.asList(dataArr));
        return decryption(keyList,dataList);
    }

    /**
     * 判断是否为空
     *
     * @param string 需要判断的参数
     * @return 判断的结果
     */
    public boolean isEmpty(String string) {
        return string == null || "".equals(string);
    }

    public static void main(String[] args) {
//        String data = "C6mcvkkzNvkGmzvCzmzvCmCzvCG2GvCN2Nvk+GGvkzmkvkm++vkGN6vkzNkvCN+NvC6zGvkzG+vk262vk2GGvCN2zvkGGNvkmCcvkCCCvkG6cvkGkcvkG62vkNk6vkc6NvkCmGvk++Cvkmz6vkG2mvCzN2vC6Nzvkm2mvC6c2vC2z2vCNcmvkGGkvkG6+vCNkmvC2z+vC6zCvkCcGvkGzzvCN2CvkGC6vkG6+vkG22vkG+2vkkGNvkC6GvkGckvkGckvCNkGvkGGGvCzN2vCC2kvCG++vC+k2vC2k2vC26zvC6mmvC62zvCN26vCNcGvCNz+vC6+GvC6k2vkG26vC6zcvC2G6vCz6GvC66zvC62mvC6z6vC6NCvkGkkvC6z+vC2NGvC6kcvC6zCvC26zvCz26vC+zkvCzG2vC2kmvCz2zvCz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CCCvkGCCvC+GNvC26zvkG+GvkG62vCN2cvCN2mvkGmNvkkmkvkkCCvkkG6vkkzGvk+k2vkckkvkCNkvkzkzvkckmvk+mzvkcN6vkG+2vC+6kvkc+kvmm22vmmNmvmck+vczz+vm+Gkvkc+6vkcc+vkczNvkm6CvkG2+vkzmzvm6mkvmC6CvmGzcvkzmCvmk22vkNzmvk2Gkvkm2CvkCc2vCNNNvC2GzvCzk2vCzz+vC6CNvC66+vC2z+vC6c+vkG+2vkCGcvkN6Gvm+z6vk22+vmmGCvmNCCvmmN6vmCckvk+CNvk6C6vkzN+vkN+cvm+zCvk2zNvk6CGvkC6zvkmGmvkGCmvCzc2vCzcGvCmGcvkGc6vkCmNvk2k6vmC6zvmmzNvmmmCvmGz2vkNC+vk2ccvmk2Cvmkk+vkNk+vkN2NvmmNmvmCC+vkNmzvk+2kvmG6zvm6mCvmGcCvkk2cvkcc+vmG+zvkcGcvkcGNvCN6cvkG2NvkC+kvkm+kvkcmCvkccCvk66zvk2m2vkk22vCNm+vkczNvmmm6vk6zGvkzN2vk6Ckvkc6zvkmGkvkkcmvkkGkvkGN+vCN+kvC2G+vCzNNvC+2CvCk62vCmNzvCNCcvkGccvk+mGvk2+Cvk+zCvkczcvk22mvkc6kvkGNmvCNc+vkz6zvkkz6vCz2+vC2GNvCN2cvCN2kvkGmzvkGG2vkGzzvkCG+vC2kNvC66cvC+GNvC+k6vCc2cvCcckvCmzkvC2mzvCzmNvC+GCvC+C+vCz+CvC6zkvC6+GvCcCCvC+k2vCNk6vCzNCvC6z+vC2mNvC6GGvC+2cvC2G2vC+m6vC+22vC+2GvCzm6vCzCCvC2+cvC+2+vCc2NvCk6kvCkCzvCG2kvCCk6vC2+zvC2kNvkGz2vkGGkvCz2CvC+czvCzk6vkk+zvC626vCzzzvCk6cvCz2GvkGCmvCcN6vCckc";
//        String key ="6+CNkJ92zG7cymv85192-%760+4.3,";
//        String decryption = decryption(key, data);
//        System.out.println(decryption);

        String content = "黄金，通胀";
        StringBuffer sb = new StringBuffer();
        sb.append("[");
//        paramMap.put("word", "[[%7B%22name%22:%22" + URLEncoder.encode(content, "UTF-8") + "%22,%22wordType%22:1%7D]]");
        Splitter.on(",").trimResults().split(content).forEach(v->{
            try {
                sb.append("[%7B%22name%22:%22" + URLEncoder.encode(content, "UTF-8") + "%22,%22wordType%22:1%7D],");
            } catch (UnsupportedEncodingException e) {
                throw new RuntimeException(e);
            }
        });
        sb.setLength(sb.length()-1);
        sb.append("]");
        System.out.println(sb.toString());
    }
}
